﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sims3Package.Wrapper
{
    /// <summary>
    /// Element visibility is used when displaying elements
    /// </summary>
    [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)]
    public class WrapperVisible : Attribute
    {
        /// <summary>
        /// Whether to show in Package Editor
        /// </summary>
        public bool Visibility { get; set; }
        /// <summary>
        /// Element priority is used when displaying elements
        /// </summary>
        /// <param name="visibility">Whether to show in Package Editor</param>
        public WrapperVisible(bool visibility) { this.Visibility = visibility; }
        /// <summary>
        /// Returns the visibility of an element
        /// </summary>
        /// <param name="t">Type</param>
        /// <param name="index">Name of property</param>
        /// <returns>Visibility of an element</returns>
        public static bool GetPriority(Type t, string index)
        {
            System.Reflection.PropertyInfo pi = t.GetProperty(index);

            if (pi != null)
                foreach (var attr in pi.GetCustomAttributes(typeof(WrapperVisible), true))
                    return (attr as WrapperVisible).Visibility;

            return false;
        }
    }
}
